Create new named boundary and group
The below code snippet shows creating new named boundary
and a group and adding the newly created named boundary to the group.
//Required References
using Bentley.DgnPlatformNET;
using Bentley.MstnPlatformNET;
using Bentley.CifNET.SDK.Edit;
using Bentley.CifNET.GeometryModel.SDK;
using Bentley.GeometryNET;
using Bentley.DgnPlatformNET.Elements;
public void CreateNamedBoundariesAndGroup()
{
//Get Active Dgn Model reference
DgnModelRef m_tempNbModel = Session.Instance.GetActiveDgnModelRef();
//Create new Consencus Connection for Edit
ConsensusConnectionEdit con = ConsensusConnectionEdit.GetActive();
//Get Geometric Model
GeometricModel gm = con.GetActiveGeometricModel();
//Check if Geometric Model is not null
if (gm == null)
{
con.Close();
con.Dispose();
return;
}
//Start transient Mode
con.StartTransientMode();
/*Create DPoints3d Array for new named Shape
Please note that x and y co-ordinates values are only for illustration purpose and user need to update those as per the requirements */
DPoint3d[] nbPoints = new DPoint3d[5];
nbPoints[0] = new DPoint3d(0, 0, 0);
nbPoints[1] = new DPoint3d(0, 200000, 0);
nbPoints[2] = new DPoint3d(400000, 200000, 0);
nbPoints[3] = new DPoint3d(400000, 0, 0);
nbPoints[4] = nbPoints[0];
//Create new Shape Element
ShapeElement nbShape = new ShapeElement(m_tempNbModel.GetDgnModel(), null, nbPoints);
//Add newly created shape to the Active Dgn Model
nbShape.AddToModel();
//Create new instance of Named Boundary object
NamedBoundary namedBoundary = new NamedBoundary();
namedBoundary.Name = "NewNamedBoundary";
namedBoundary.Description = "FirstNamedBoundaryUsingSDK";
namedBoundary.ModelRef = m_tempNbModel;
namedBoundary.GraphicalElement = nbShape;
//Save Named Boundary
if (StatusInt.Success != namedBoundary.Save())
return;
//Create new Named Boundary Group
NamedBoundaryGroup nbGroup = Bentley.DgnPlatformNET.NamedBoundaryGroup.CreateNamedBoundaryGroup(m_tempNbModel.GetDgnModel(), "NewNbGroup", "NewNbGroup");
//Insert Named Boundary in Named Boundary Group
nbGroup.InsertBoundary(namedBoundary);
//Write Named Boundary Group to file
if (StatusInt.Success != nbGroup.WriteToFile())
return;
//Persist Transient
con.PersistTransients();
}
Output
This code generated an output like shown in below image.